package DateUtil;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by areehy on 2016/8/12.
 */
public class TaskDb extends SQLiteOpenHelper {
    public static final String CREATE_MESSAGE = "create table task("
            + "taskid integer primary key , "
            + "tasktime text,"
            + "taskupman text,"
            + "taskinfo text,"
            + "taskstate integer)";
    private Context mContext;

    public TaskDb(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
    {
        super(context,name,factory,version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MESSAGE);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Toast.makeText(mContext, "更新数据库", Toast.LENGTH_SHORT).show();
    }
    public void addvalue(SQLiteDatabase db,  int taskid, String tasktime, String taskupman, String taskinfo, int taskstate)
    {
        ContentValues cv = new ContentValues();
        cv.put("taskstate",taskstate);
        cv.put("taskinfo",taskinfo);
        cv.put("taskupman",taskupman);
        cv.put("tasktime",tasktime);
        cv.put("taskid",taskid);
        db.insert("task", null, cv);

    }
    public void replacevalue(SQLiteDatabase db,  int taskid, String tasktime, String taskupman, String taskinfo, int taskstate){
        ContentValues cv = new ContentValues();
        cv.put("taskstate",taskstate);
        cv.put("taskinfo",taskinfo);
        cv.put("taskupman",taskupman);
        cv.put("tasktime",tasktime);
        cv.put("taskid",taskid);
        db.replace("task", null, cv);
    }
}
